﻿using IBLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.SessionState;

namespace SysHelper
{
    public partial class OperateContext
    {
        HttpContext httpContext { get { return HttpContext.Current; } }

        HttpRequest Request { get { return httpContext.Request; } }

        HttpResponse Response { get { return httpContext.Response; } }

        HttpSessionState Session { get { return httpContext.Session; } }
    }

    public partial class OperateContext
    {
        #region 通过构造函数实例化 业务仓储    BllSession

        public IBLLSession BllSession;

        public OperateContext()
        {
            BllSession = DI.Spring.GetObject<IBLLSession>("BLLSession");
        }
        #endregion
    }

    public partial class OperateContext
    {
        #region 获取当前 操作上下文  OperateContext CurrentContext
        public static OperateContext CurrentContext
        {
            get
            {
                OperateContext context = CallContext.GetData(typeof(OperateContext).Name) as OperateContext;
                if (context == null)
                {
                    context = new OperateContext();
                    CallContext.SetData(typeof(OperateContext).Name, context);
                }
                return context;
            }
        }

        #endregion
    }

    public partial class OperateContext
    {
        #region 生成 Json 格式的返回值 + RedirectAjax(string statu, string msg, object data, string backurl)
        /// <summary>
        /// 生成 Json 格式的返回值
        /// </summary>
        /// <param name="statu"></param>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <param name="backurl"></param>
        /// <returns></returns>
        public ActionResult RedirectAjax(string statu, string msg, object data, string backurl)
        {
            AjaxMsgModel ajax = new AjaxMsgModel()
            {
                Statu = statu,
                Msg = msg,
                Data = data,
                BackUrl = backurl
            };
            JsonResult res = new JsonResult();
            res.Data = ajax;
            res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return res;
        }
        #endregion
    }

}
